-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make in-memory Merkle tree immutable #2701
Conversation
af66de7
to
5c6d926
Compare
5c6d926
to
914ee91
Compare
91737c9
to
59220f5
Compare
On a second thought, perhaps it's better to leave this type as is, so that it's simpler. It is used only for testing, so it should be intuitive. The "feature" of this approach allows implementing transactions on Merkle trees. For example, in an in-memory Merkle tree storage. However, I don't think we would need it soon. |
Making |
Please review #2706 instead. |
@@ -124,16 +124,16 @@ var testProofs = []proofTestVector{ | |||
}}, | |||
} | |||
|
|||
func decodeHexStringOrPanic(hs string) []byte { | |||
// hx decodes a hex string or panics. | |||
func hx(hs string) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to this CL, right?
Although I like the shortness, after this PR, it is unclear from looking at the name of this function wether is decodes or encodes a string in hex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this could be separated, I just did it as a drive-by because otherwise the lists of constants would look too verbose.
This file was old and ugly anyway, so #2707 refactors it. After the refactoring, hx
is used only with constants that are inlined, e.g. hx("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d")
, and never used with variables like hx(someVariable)
. So it's obvious from context that it decodes, and the pros is that the name is short.
This change makes the
inmemory.Tree
Merkle tree type behave similarly to a regular Go slice.It provides variadic
Append*
methods which most of the time reuse memory, but may reallocateand copy data. It is safe to reuse all previous
Tree
objects for reads, and it is possible to rollback and use for writes (with caution, knowing that it may rewrite hashes of any bigger
Tree
).